package com.frxuexi.docments

import com.frxuexi.lib_base.entity.ApiResponse
import com.frxuexi.lib_base.BaseViewModel
import com.frxuexi.lib_base.RequestType
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class DocViewModel @Inject constructor(private val docRepository: DocRepository):BaseViewModel<DocIntent> (){
    override fun handleIntent(it: DocIntent) {
        when(it){
            is DocIntent.getDoc->{
                httpRequest(docRepository.getDocs(it.map) as Flow<ApiResponse<Any>>)
            }
            is DocIntent.deleteDoc->{
                httpRequest(docRepository.deleteDocs(mapOf("FileId" to it.fildId)) as Flow<ApiResponse<Any>>,RequestType.DELETE)
            }
            is DocIntent.scanFiles->{
                scanFiles(it.file)
            }
            is DocIntent.uploadFile->{
                httpRequest(docRepository.uploadDoc(it.name,it.path) as Flow<ApiResponse<Any>>,RequestType.UPLOAD)
            }

            else -> {}
        }
    }
}